#include "gtklistitemfactory.h"
#include "gtklistitemmanagerprivate.h"
#include "gtkmain.h"
-#include "gtkorientableprivate.h"
#include "gtkprivate.h"
#include "gtksingleselection.h"
-#include "gtktypebuiltins.h"
#include "gtkwidgetprivate.h"
/* Maximum number of list items created by the gridview.
GListModel *model;
GtkListItemManager *item_manager;
- GtkOrientation orientation;
guint min_columns;
guint max_columns;
/* set in size_allocate */
PROP_MAX_COLUMNS,
PROP_MIN_COLUMNS,
PROP_MODEL,
- PROP_ORIENTATION,
N_PROPS
};
LAST_SIGNAL
};
-G_DEFINE_TYPE_WITH_CODE (GtkGridView, gtk_grid_view, GTK_TYPE_LIST_BASE,
- G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL))
+G_DEFINE_TYPE (GtkGridView, gtk_grid_view, GTK_TYPE_LIST_BASE)
static GParamSpec *properties[N_PROPS] = { NULL, };
static guint signals[LAST_SIGNAL] = { 0 };
anchor_pos = gtk_list_item_tracker_get_position (self->item_manager, self->anchor);
n_items = g_list_model_get_n_items (self->model);
- if (orientation == self->orientation)
+ if (orientation == gtk_list_base_get_orientation (GTK_LIST_BASE (self)))
{
/* Compute how far down we've scrolled. That's the height
* we want to align to. */
* to fill the row.
* Do it the hard way then... */
gtk_list_base_get_adjustment_values (base,
- OPPOSITE_ORIENTATION (self->orientation),
+ gtk_list_base_get_opposite_orientation (base),
&value, &total_size, &page_size);
pos = n_items - 1;
page_size = gtk_widget_get_size (GTK_WIDGET (self), orientation);
- if (self->orientation == orientation)
+ if (gtk_list_base_get_orientation (GTK_LIST_BASE (self)) == orientation)
{
Cell *cell;
CellAugment *aug;
value += cell_size;
value = gtk_list_base_set_adjustment_values (GTK_LIST_BASE (self),
- self->orientation,
+ orientation,
value - self->anchor_yalign * page_size,
aug->size,
page_size);
total_size = round (self->n_columns * self->column_width);
value = gtk_list_base_set_adjustment_values (GTK_LIST_BASE (self),
- OPPOSITE_ORIENTATION (self->orientation),
+ orientation,
value - self->anchor_xalign * page_size,
total_size,
page_size);
min = 0;
nat = 0;
- opposite = OPPOSITE_ORIENTATION (self->orientation);
+ opposite = gtk_list_base_get_opposite_orientation (GTK_LIST_BASE (self));
for (cell = gtk_list_item_manager_get_first (self->item_manager);
cell != NULL;
guint n_columns;
/* rounding down is exactly what we want here, so int division works */
- if (gtk_list_base_get_scroll_policy (GTK_LIST_BASE (self), OPPOSITE_ORIENTATION (self->orientation)) == GTK_SCROLL_MINIMUM)
+ if (gtk_list_base_get_scroll_policy (GTK_LIST_BASE (self),
+ gtk_list_base_get_opposite_orientation (GTK_LIST_BASE (self))) == GTK_SCROLL_MINIMUM)
n_columns = for_size / MAX (1, min);
else
n_columns = for_size / MAX (1, nat);
guint n_unknown, n_columns;
guint i;
- scroll_policy = gtk_list_base_get_scroll_policy (GTK_LIST_BASE (self), self->orientation);
+ scroll_policy = gtk_list_base_get_scroll_policy (GTK_LIST_BASE (self), gtk_list_base_get_orientation (GTK_LIST_BASE (self)));
heights = g_array_new (FALSE, FALSE, sizeof (int));
n_unknown = 0;
height = 0;
if (cell->parent.widget)
{
gtk_widget_measure (cell->parent.widget,
- self->orientation, column_size,
+ gtk_list_base_get_orientation (GTK_LIST_BASE (self)),
+ column_size,
&child_min, &child_nat, NULL, NULL);
if (scroll_policy == GTK_SCROLL_MINIMUM)
row_height = MAX (row_height, child_min);
{
GtkGridView *self = GTK_GRID_VIEW (widget);
- if (orientation == self->orientation)
+ if (orientation == gtk_list_base_get_orientation (GTK_LIST_BASE (self)))
gtk_grid_view_measure_list (widget, for_size, minimum, natural);
else
gtk_grid_view_measure_across (widget, for_size, minimum, natural);
{
GtkAllocation child_allocation;
- if (self->orientation == GTK_ORIENTATION_VERTICAL)
+ if (gtk_list_base_get_orientation (GTK_LIST_BASE (self)) == GTK_ORIENTATION_VERTICAL)
{
child_allocation.x = x;
child_allocation.y = y;
Cell *cell, *start;
GArray *heights;
int min_row_height, row_height, col_min, col_nat;
- GtkOrientation opposite_orientation;
+ GtkOrientation orientation, opposite_orientation;
GtkScrollablePolicy scroll_policy;
gboolean known;
int x, y;
guint i;
- scroll_policy = gtk_list_base_get_scroll_policy (GTK_LIST_BASE (self), self->orientation);
- opposite_orientation = OPPOSITE_ORIENTATION (self->orientation);
+ orientation = gtk_list_base_get_orientation (GTK_LIST_BASE (self));
+ scroll_policy = gtk_list_base_get_scroll_policy (GTK_LIST_BASE (self), orientation);
+ opposite_orientation = OPPOSITE_ORIENTATION (orientation);
min_row_height = ceil ((double) height / GTK_GRID_VIEW_MAX_VISIBLE_ROWS);
/* step 0: exit early if list is empty */
/* step 1: determine width of the list */
gtk_grid_view_measure_column_size (self, &col_min, &col_nat);
self->n_columns = gtk_grid_view_compute_n_columns (self,
- self->orientation == GTK_ORIENTATION_VERTICAL ? width : height,
+ orientation == GTK_ORIENTATION_VERTICAL ? width : height,
col_min, col_nat);
- self->column_width = (self->orientation == GTK_ORIENTATION_VERTICAL ? width : height) / self->n_columns;
+ self->column_width = (orientation == GTK_ORIENTATION_VERTICAL ? width : height) / self->n_columns;
self->column_width = MAX (self->column_width, col_min);
/* step 2: determine height of known rows */
if (cell->parent.widget)
{
int min, nat, size;
- gtk_widget_measure (cell->parent.widget, self->orientation,
+ gtk_widget_measure (cell->parent.widget,
+ gtk_list_base_get_orientation (GTK_LIST_BASE (self)),
self->column_width,
&min, &nat, NULL, NULL);
if (scroll_policy == GTK_SCROLL_MINIMUM)
/* step 4: update the adjustments */
x = - gtk_grid_view_update_adjustment (self, opposite_orientation);
- y = - gtk_grid_view_update_adjustment (self, self->orientation);
+ y = - gtk_grid_view_update_adjustment (self, orientation);
/* step 5: run the size_allocate loop */
x = -x;
g_value_set_object (value, self->model);
break;
- case PROP_ORIENTATION:
- g_value_set_enum (value, self->orientation);
- break;
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
gtk_grid_view_set_min_columns (self, g_value_get_uint (value));
break;
- case PROP_ORIENTATION:
- {
- GtkOrientation orientation = g_value_get_enum (value);
- if (self->orientation != orientation)
- {
- self->orientation = orientation;
- _gtk_orientable_set_style_classes (GTK_ORIENTABLE (self));
- gtk_widget_queue_resize (GTK_WIDGET (self));
- g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ORIENTATION]);
- }
- }
- break;
-
case PROP_MODEL:
gtk_grid_view_set_model (self, g_value_get_object (value));
break;
end += start;
gtk_grid_view_compute_scroll_align (self,
- self->orientation,
+ gtk_list_base_get_orientation (GTK_LIST_BASE (self)),
start, end,
self->anchor_yalign, self->anchor_ystart,
&yalign, &ystart);
start = floor (self->column_width * (pos % self->n_columns));
end = floor (self->column_width * ((pos % self->n_columns) + 1));
gtk_grid_view_compute_scroll_align (self,
- OPPOSITE_ORIENTATION (self->orientation),
+ gtk_list_base_get_opposite_orientation (GTK_LIST_BASE (self)),
start, end,
self->anchor_xalign, self->anchor_xstart,
&xalign, &xstart);
g_variant_get (args, "(ubbbi)", &orientation, &select, &modify, &extend, &amount);
- if (self->orientation == orientation)
+ if (gtk_list_base_get_orientation (GTK_LIST_BASE (self)) == orientation)
amount *= self->n_columns;
if (orientation == GTK_ORIENTATION_HORIZONTAL &&
if (!gtk_grid_view_get_size_at_position (self, pos, &start, &size))
return TRUE;
gtk_list_base_get_adjustment_values (GTK_LIST_BASE (self),
- self->orientation,
+ gtk_list_base_get_orientation (GTK_LIST_BASE (self)),
NULL, NULL, &page_size);
if (!gtk_grid_view_get_cell_at_y (self,
MAX (0, start + size - page_size),
if (!gtk_grid_view_get_size_at_position (self, pos, &start, NULL))
return TRUE;
gtk_list_base_get_adjustment_values (GTK_LIST_BASE (self),
- self->orientation,
+ gtk_list_base_get_orientation (GTK_LIST_BASE (self)),
NULL, NULL, &page_size);
if (gtk_grid_view_get_cell_at_y (self,
start + page_size,
G_TYPE_LIST_MODEL,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
- /**
- * GtkGridView:orientation:
- *
- * The orientation of the gridview. See GtkOrientable:orientation
- * for details.
- */
- properties[PROP_ORIENTATION] =
- g_param_spec_enum ("orientation",
- P_("Orientation"),
- P_("The orientation of the orientable"),
- GTK_TYPE_ORIENTATION,
- GTK_ORIENTATION_VERTICAL,
- GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
-
g_object_class_install_properties (gobject_class, N_PROPS, properties);
/**
self->min_columns = 1;
self->max_columns = DEFAULT_MAX_COLUMNS;
- self->orientation = GTK_ORIENTATION_VERTICAL;
}
/**
#include "gtklistbaseprivate.h"
#include "gtkadjustment.h"
+#include "gtkintl.h"
+#include "gtkorientableprivate.h"
#include "gtkscrollable.h"
+#include "gtktypebuiltins.h"
typedef struct _GtkListBasePrivate GtkListBasePrivate;
struct _GtkListBasePrivate
{
GtkListItemManager *item_manager;
+ GtkOrientation orientation;
GtkAdjustment *adjustment[2];
GtkScrollablePolicy scroll_policy[2];
PROP_0,
PROP_HADJUSTMENT,
PROP_HSCROLL_POLICY,
+ PROP_ORIENTATION,
PROP_VADJUSTMENT,
PROP_VSCROLL_POLICY,
#define g_type_register_static_simple(a,b,c,d,e,evil,f) g_type_register_static_simple(a,b,c,d,e, (GInstanceInitFunc) gtk_list_base_init_real, f);
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GtkListBase, gtk_list_base, GTK_TYPE_WIDGET,
G_ADD_PRIVATE (GtkListBase)
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL)
G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
#undef g_type_register_static_simple
G_GNUC_UNUSED static void gtk_list_base_init (GtkListBase *self) { }
g_value_set_enum (value, priv->scroll_policy[GTK_ORIENTATION_HORIZONTAL]);
break;
+ case PROP_ORIENTATION:
+ g_value_set_enum (value, priv->orientation);
+ break;
+
case PROP_VADJUSTMENT:
g_value_set_object (value, priv->adjustment[GTK_ORIENTATION_VERTICAL]);
break;
GParamSpec *pspec)
{
GtkListBase *self = GTK_LIST_BASE (object);
+ GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
switch (property_id)
{
gtk_list_base_set_scroll_policy (self, GTK_ORIENTATION_HORIZONTAL, g_value_get_enum (value));
break;
+ case PROP_ORIENTATION:
+ {
+ GtkOrientation orientation = g_value_get_enum (value);
+ if (priv->orientation != orientation)
+ {
+ priv->orientation = orientation;
+ _gtk_orientable_set_style_classes (GTK_ORIENTABLE (self));
+ gtk_widget_queue_resize (GTK_WIDGET (self));
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ORIENTATION]);
+ }
+ }
+ break;
+
case PROP_VADJUSTMENT:
gtk_list_base_set_adjustment (self, GTK_ORIENTATION_VERTICAL, g_value_get_object (value));
break;
g_param_spec_override ("vscroll-policy",
g_object_interface_find_property (iface, "vscroll-policy"));
+ /**
+ * GtkListBase:orientation:
+ *
+ * The orientation of the list. See GtkOrientable:orientation
+ * for details.
+ */
+ properties[PROP_ORIENTATION] =
+ g_param_spec_enum ("orientation",
+ P_("Orientation"),
+ P_("The orientation of the orientable"),
+ GTK_TYPE_ORIENTATION,
+ GTK_ORIENTATION_VERTICAL,
+ G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_EXPLICIT_NOTIFY);
+
g_object_class_install_properties (gobject_class, N_PROPS, properties);
/**
g_class->list_item_size,
g_class->list_item_augment_size,
g_class->list_item_augment_func);
-
priv->selected = gtk_list_item_tracker_new (priv->item_manager);
priv->adjustment[GTK_ORIENTATION_HORIZONTAL] = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
priv->adjustment[GTK_ORIENTATION_VERTICAL] = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
+ priv->orientation = GTK_ORIENTATION_VERTICAL;
+
gtk_widget_set_overflow (GTK_WIDGET (self), GTK_OVERFLOW_HIDDEN);
gtk_widget_set_focusable (GTK_WIDGET (self), TRUE);
}
return priv->scroll_policy[orientation];
}
+GtkOrientation
+gtk_list_base_get_orientation (GtkListBase *self)
+{
+ GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
+
+ return priv->orientation;
+}
+
GtkListItemManager *
gtk_list_base_get_manager (GtkListBase *self)
{
#include "gtklistbase.h"
#include "gtklistitemmanagerprivate.h"
+#include "gtkprivate.h"
struct _GtkListBase
{
GtkOrientation orientation);
};
+GtkOrientation gtk_list_base_get_orientation (GtkListBase *self);
+#define gtk_list_base_get_opposite_orientation(self) OPPOSITE_ORIENTATION(gtk_list_base_get_orientation(self))
GtkListItemManager * gtk_list_base_get_manager (GtkListBase *self);
GtkScrollablePolicy gtk_list_base_get_scroll_policy (GtkListBase *self,
GtkOrientation orientation);
#include "gtklistbaseprivate.h"
#include "gtklistitemmanagerprivate.h"
#include "gtkmain.h"
-#include "gtkorientableprivate.h"
#include "gtkprivate.h"
#include "gtkrbtreeprivate.h"
#include "gtkselectionmodel.h"
#include "gtksingleselection.h"
#include "gtkstylecontext.h"
-#include "gtktypebuiltins.h"
#include "gtkwidgetprivate.h"
/* Maximum number of list items created by the listview.
GListModel *model;
GtkListItemManager *item_manager;
gboolean show_separators;
- GtkOrientation orientation;
int list_width;
PROP_0,
PROP_FACTORY,
PROP_MODEL,
- PROP_ORIENTATION,
PROP_SHOW_SEPARATORS,
N_PROPS
LAST_SIGNAL
};
-G_DEFINE_TYPE_WITH_CODE (GtkListView, gtk_list_view, GTK_TYPE_LIST_BASE,
- G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL))
+G_DEFINE_TYPE (GtkListView, gtk_list_view, GTK_TYPE_LIST_BASE)
static GParamSpec *properties[N_PROPS] = { NULL, };
static guint signals[LAST_SIGNAL] = { 0 };
{
GtkListView *self = GTK_LIST_VIEW (base);
- if (orientation == self->orientation)
+ if (orientation == gtk_list_base_get_orientation (GTK_LIST_BASE (self)))
{
int page_size, total_size, value, from_start;
int row_start, row_end;
page_size = gtk_widget_get_size (GTK_WIDGET (self), orientation);
- if (orientation == self->orientation)
+ if (orientation == gtk_list_base_get_orientation (GTK_LIST_BASE (self)))
{
int offset, size;
guint anchor_pos;
{
GtkListView *self = GTK_LIST_VIEW (widget);
- if (orientation == self->orientation)
+ if (orientation == gtk_list_base_get_orientation (GTK_LIST_BASE (self)))
gtk_list_view_measure_list (widget, orientation, for_size, minimum, natural);
else
gtk_list_view_measure_across (widget, orientation, for_size, minimum, natural);
{
GtkAllocation child_allocation;
- if (self->orientation == GTK_ORIENTATION_VERTICAL)
+ if (gtk_list_base_get_orientation (GTK_LIST_BASE (self)) == GTK_ORIENTATION_VERTICAL)
{
child_allocation.x = x;
child_allocation.y = y;
GArray *heights;
int min, nat, row_height;
int x, y;
- GtkOrientation opposite_orientation;
+ GtkOrientation orientation, opposite_orientation;
GtkScrollablePolicy scroll_policy;
- opposite_orientation = OPPOSITE_ORIENTATION (self->orientation);
- scroll_policy = gtk_list_base_get_scroll_policy (GTK_LIST_BASE (self), self->orientation);
+ orientation = gtk_list_base_get_orientation (GTK_LIST_BASE (self));
+ opposite_orientation = OPPOSITE_ORIENTATION (orientation);
+ scroll_policy = gtk_list_base_get_scroll_policy (GTK_LIST_BASE (self), orientation);
/* step 0: exit early if list is empty */
if (gtk_list_item_manager_get_root (self->item_manager) == NULL)
gtk_widget_measure (widget, opposite_orientation,
-1,
&min, &nat, NULL, NULL);
- self->list_width = self->orientation == GTK_ORIENTATION_VERTICAL ? width : height;
+ self->list_width = orientation == GTK_ORIENTATION_VERTICAL ? width : height;
if (scroll_policy == GTK_SCROLL_MINIMUM)
self->list_width = MAX (min, self->list_width);
else
if (row->parent.widget == NULL)
continue;
- gtk_widget_measure (row->parent.widget, self->orientation,
+ gtk_widget_measure (row->parent.widget, orientation,
self->list_width,
&min, &nat, NULL, NULL);
if (scroll_policy == GTK_SCROLL_MINIMUM)
/* step 3: update the adjustments */
x = - gtk_list_view_update_adjustments (self, opposite_orientation);
- y = - gtk_list_view_update_adjustments (self, self->orientation);
+ y = - gtk_list_view_update_adjustments (self, orientation);
/* step 4: actually allocate the widgets */
g_value_set_object (value, self->model);
break;
- case PROP_ORIENTATION:
- g_value_set_enum (value, self->orientation);
- break;
-
case PROP_SHOW_SEPARATORS:
g_value_set_boolean (value, self->show_separators);
break;
gtk_list_view_set_model (self, g_value_get_object (value));
break;
- case PROP_ORIENTATION:
- {
- GtkOrientation orientation = g_value_get_enum (value);
- if (self->orientation != orientation)
- {
- self->orientation = orientation;
- _gtk_orientable_set_style_classes (GTK_ORIENTABLE (self));
- gtk_widget_queue_resize (GTK_WIDGET (self));
- g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ORIENTATION]);
- }
- }
- break;
-
case PROP_SHOW_SEPARATORS:
gtk_list_view_set_show_separators (self, g_value_get_boolean (value));
break;
end += start;
gtk_list_view_compute_scroll_align (self,
- self->orientation,
+ gtk_list_base_get_orientation (GTK_LIST_BASE (self)),
start, end,
self->anchor_align, self->anchor_start,
&align, &top);
g_variant_get (args, "(ubbbi)", &orientation, &select, &modify, &extend, &amount);
- if (self->orientation != orientation)
+ if (gtk_list_base_get_orientation (GTK_LIST_BASE (self)) != orientation)
return TRUE;
if (orientation == GTK_ORIENTATION_HORIZONTAL &&
if (n_items == 0 || start == 0)
return TRUE;
- if (self->orientation == GTK_ORIENTATION_HORIZONTAL)
- pixels = gtk_widget_get_width (widget);
- else
- pixels = gtk_widget_get_height (widget);
+ pixels = gtk_widget_get_size (widget, gtk_list_base_get_orientation (GTK_LIST_BASE (self)));
pixels -= row->height;
pos = gtk_list_view_get_position_at_y (self,
if (n_items == 0 || start >= n_items - 1)
return TRUE;
- if (self->orientation == GTK_ORIENTATION_HORIZONTAL)
- pixels = gtk_widget_get_width (widget);
- else
- pixels = gtk_widget_get_height (widget);
+ pixels = gtk_widget_get_size (widget, gtk_list_base_get_orientation (GTK_LIST_BASE (self)));
pos = gtk_list_view_get_position_at_y (self,
list_row_get_y (self, row) + pixels,
G_TYPE_LIST_MODEL,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
- /**
- * GtkListView:orientation:
- *
- * The orientation of the orientable. See GtkOrientable:orientation
- * for details.
- */
- properties[PROP_ORIENTATION] =
- g_param_spec_enum ("orientation",
- P_("Orientation"),
- P_("The orientation of the orientable"),
- GTK_TYPE_ORIENTATION,
- GTK_ORIENTATION_VERTICAL,
- GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
-
/**
* GtkListView:show-separators:
*
self->item_manager = gtk_list_base_get_manager (GTK_LIST_BASE (self));
self->focus = gtk_list_item_tracker_new (self->item_manager);
self->anchor = gtk_list_item_tracker_new (self->item_manager);
- self->orientation = GTK_ORIENTATION_VERTICAL;
}
/**